package com.zrar.ak.gkpt.service.impl.record;

import com.zrar.ak.gkpt.dao.*;
import com.zrar.ak.gkpt.model.bo.*;
import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.common.ICirculationDetailsService;
import com.zrar.ak.gkpt.service.record.IRecordInformationService;
import com.zrar.ak.gkpt.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.*;

@Service
public class RecordInformationService implements IRecordInformationService {

    @Autowired
    private IFormRecordContractTDao formRecordContractTDao;
    @Autowired
    private IFormRecordContractTerminalTiDao formRecordContractTerminalTiDao;
    @Autowired
    private IFormRecordContractServerTiDao formRecordContractServerTiDao;
    @Autowired
    private IFormRecordContractSystemTiDao formRecordContractSystemTiDao;

    @Autowired
    private IFormRecordBidTDao formRecordBidTDao;
    @Autowired
    private IFormRecordAcceptTDao formRecordAcceptTDao;
    @Autowired
    private IFormRecordFundsTDao  formRecordFundsTDao;

    @Autowired
    private ICirculationDetailsService circulationDetailsService;

    @Autowired
    private IFormRecordFundsHistoryTDao formRecordFundsHistoryTDao;

    @Autowired
    private IAccountInformationDao accountInformationDao;

    @Autowired
    private IFormBuildUnitTDao formBuildUnitTDao;

    @Autowired
    private IRecordInformationDao recordInformationDao;

    @Override
    @Transactional
    public JsonResult recordAssign(JsonResult jsonResult, FormDataParameter formDataParameter, UserVO userVO) throws Exception{
        //流转明细业务类型(1.招投标备案 2.合同备案 3.验收备案 4.资金使用备案)
        String businessTypeString = formDataParameter.getBusinessType();

        String[] businessTypeArrays = businessTypeString.split(",");
        String formDataJson = formDataParameter.getFormDataJson();

        Map map = CommonTools.jsonStrToObject(formDataJson, Map.class);
        //建设单位编码
        String buildUnitCodeString = (String)map.get("buildUnitCode");
        String[] buildUnitCodeArrays = buildUnitCodeString.split(",");

        for(String businessType : businessTypeArrays){
            for(String buildUnitCode : buildUnitCodeArrays){
                Boolean bool = circulationDetailsService.canRecordAssign(businessType, buildUnitCode);
                String uuid = CommonTools.getUUID();
                if(!bool){
                    //不符合下发条件，比如该建设单位还存在正在流转的对应的备案业务
                    CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_EXISTENT_DATA);
                }else{
                    if(BusinessEnum.BUSINESS_TYPE_RECORD_BID.getValue().equals(businessType)){
                        //招投标备案
                        //招投标附件模板对应附件表的主键
                        String bidAnnexTemplate = (String)map.get("bidAnnexTemplate");
                        //招投标附件模板名字
                        String bidAnnexTemplateName = (String)map.get("bidAnnexTemplateName");
                        FormRecordBidTBO formRecord = new FormRecordBidTBO();
                        formRecord.setId(uuid);
                        formRecord.setCreatorId(userVO.getUserId());
                        formRecord.setCreateTime(new Date());
                        formRecord.setUpdateUserId(userVO.getUserId());
                        formRecord.setUpdateTime(new Date());
                        formRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                        formRecord.setBuildUnitCode(buildUnitCode);
                        formRecord.setBusinessStatus(BusinessEnum.BUSINESS_STATUS_REPLY_N.getValue());
                        formRecord.setBidAnnexTemplate(bidAnnexTemplate);
                        formRecord.setBidAnnexTemplateName(bidAnnexTemplateName);
                        int insert = formRecordBidTDao.insert(formRecord);
                    }else if(BusinessEnum.BUSINESS_TYPE_RECORD_CONTRACT.getValue().equals(businessType)){
                        //合同备案
                        FormRecordContractTBO formRecord = new FormRecordContractTBO();
                        formRecord.setId(uuid);
                        formRecord.setCreatorId(userVO.getUserId());
                        formRecord.setCreateTime(new Date());
                        formRecord.setUpdateUserId(userVO.getUserId());
                        formRecord.setUpdateTime(new Date());
                        formRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                        formRecord.setBuildUnitCode(buildUnitCode);
                        formRecord.setBusinessStatus(BusinessEnum.BUSINESS_STATUS_REPLY_N.getValue());
                        int insert = formRecordContractTDao.insert(formRecord);
                    }else if(BusinessEnum.BUSINESS_TYPE_RECORD_ACCEPT.getValue().equals(businessType)){
                        //验收备案
                        FormRecordAcceptTBO formRecord = new FormRecordAcceptTBO();
                        formRecord.setId(uuid);
                        formRecord.setCreatorId(userVO.getUserId());
                        formRecord.setCreateTime(new Date());
                        formRecord.setUpdateUserId(userVO.getUserId());
                        formRecord.setUpdateTime(new Date());
                        formRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                        formRecord.setBuildUnitCode(buildUnitCode);
                        formRecord.setBusinessStatus(BusinessEnum.BUSINESS_STATUS_REPLY_N.getValue());
                        int insert = formRecordAcceptTDao.insert(formRecord);
                    }else if(BusinessEnum.BUSINESS_TYPE_RECORD_FUNDS.getValue().equals(businessType)){
                        //资金使用备案
                        FormRecordFundsTBO formRecord = new FormRecordFundsTBO();
                        formRecord.setId(uuid);
                        formRecord.setCreatorId(userVO.getUserId());
                        formRecord.setCreateTime(new Date());
                        formRecord.setUpdateUserId(userVO.getUserId());
                        formRecord.setUpdateTime(new Date());
                        formRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                        formRecord.setBuildUnitCode(buildUnitCode);
                        formRecord.setBusinessStatus(BusinessEnum.BUSINESS_STATUS_REPLY_N.getValue());
                        int insert1 = formRecordFundsTDao.insert(formRecord);
                        //资金使用历史痕迹保存
                        FormRecordFundsHistoryTBO formRecordFundsHistoryTBO = CommonTools.convertBean(formRecord, FormRecordFundsHistoryTBO.class);
                        formRecordFundsHistoryTBO.setRecordFundsHistoryId(CommonTools.getUUID());
                        int insert2 = formRecordFundsHistoryTDao.insert(formRecordFundsHistoryTBO);
                    }
                    circulationDetailsService.saveCirculationDetails(uuid, businessType, BusinessEnum.CIRCULATION_STATUS_ASSIGN.getValue(), buildUnitCode, null, userVO);
                }
            }
        }
        CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        return jsonResult;
    }

    @Override
    @Transactional
    public JsonResult recordCirculation(JsonResult jsonResult,  FormDataParameter formDataParameter, UserVO userVO) throws Exception{
        //流转明细业务类型(1.招投标备案 2.合同备案 3.验收备案 4.资金使用备案)
        String businessType = formDataParameter.getBusinessType();
        //流转状态(1.下发 2.回复 3.退回修改 4.结束)
        String circulationStatus = formDataParameter.getCirculationStatus();
        //备案业务状态
        String recordBusinessStatus = BusinessCommonTools.circulationStatusToRecordBusinessStatus(circulationStatus);
        //处理意见
        String handlingOpinions = formDataParameter.getHandlingOpinions();
        //业务数据json串
        String formDataJson = formDataParameter.getFormDataJson();

        if(BusinessEnum.BUSINESS_TYPE_RECORD_BID.equals(businessType)){
            //招投标备案
            //传入的数据
            FormRecordBidTBO newFormRecord = CommonTools.jsonStrToObject(formDataJson, FormRecordBidTBO.class);
            //数据库的数据
            FormRecordBidTBO oldFormRecord = formRecordBidTDao.selectByPrimaryKey(newFormRecord.getId());
            //结合数据库的数据对传入的数据进行完善然后覆盖数据库的数据
            newFormRecord.setCreatorId(oldFormRecord.getCreatorId());
            newFormRecord.setCreateTime(oldFormRecord.getCreateTime());
            newFormRecord.setUpdateUserId(userVO.getUserId());
            newFormRecord.setUpdateTime(new Date());
            newFormRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            newFormRecord.setBuildUnitCode(oldFormRecord.getBuildUnitCode());
            newFormRecord.setBusinessStatus(recordBusinessStatus);
            formRecordBidTDao.updateByPrimaryKey(newFormRecord);
            circulationDetailsService.saveCirculationDetails(newFormRecord.getId(), businessType, circulationStatus, newFormRecord.getBuildUnitCode(), handlingOpinions, userVO);
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        }else if(BusinessEnum.BUSINESS_TYPE_RECORD_CONTRACT.equals(businessType)){
            //合同备案
            //传入的数据
            FormRecordContractTBO newFormRecord = CommonTools.jsonStrToObject(formDataJson, FormRecordContractTBO.class);
            //数据库的数据
            FormRecordContractTBO oldFormRecord = formRecordContractTDao.getRecordContractByContractId(newFormRecord.getId());
            newFormRecord.setCreatorId(oldFormRecord.getCreatorId());
            newFormRecord.setCreateTime(oldFormRecord.getCreateTime());
            newFormRecord.setUpdateUserId(userVO.getUserId());
            newFormRecord.setUpdateTime(new Date());
            newFormRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            newFormRecord.setBuildUnitCode(oldFormRecord.getBuildUnitCode());
            newFormRecord.setBusinessStatus(recordBusinessStatus);
            newFormRecord.setBusinessStatus(recordBusinessStatus);
            formRecordContractTDao.updateByPrimaryKey(newFormRecord);

            //删除子表数据
            formRecordContractTerminalTiDao.deleteByContractId(newFormRecord.getId());
            formRecordContractServerTiDao.deleteByContractId(newFormRecord.getId());
            formRecordContractSystemTiDao.deleteByContractId(newFormRecord.getId());
            //添加子表数据
            //备案信息表_合同备案_终端_子表
            for(FormRecordContractTerminalTiBO formRecordContractTerminalTiBO : newFormRecord.getFormRecordContractTerminalTiBOList()){
                formRecordContractTerminalTiBO.setId(CommonTools.getUUID());
                formRecordContractTerminalTiBO.setCreatorId(newFormRecord.getCreatorId());
                formRecordContractTerminalTiBO.setCreateTime(newFormRecord.getCreateTime());
                formRecordContractTerminalTiBO.setUpdateUserId(newFormRecord.getUpdateUserId());
                formRecordContractTerminalTiBO.setUpdateTime(newFormRecord.getUpdateTime());
                formRecordContractTerminalTiBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                formRecordContractTerminalTiBO.setBuildUnitCode(newFormRecord.getBuildUnitCode());
                formRecordContractTerminalTiBO.setContractId(newFormRecord.getId());
                formRecordContractTerminalTiDao.insert(formRecordContractTerminalTiBO);
            }
            //备案信息表_合同备案_服务器_子表
            for(FormRecordContractServerTiBO formRecordContractServerTiBO : newFormRecord.getFormRecordContractServerTiBOList()){
                formRecordContractServerTiBO.setId(CommonTools.getUUID());
                formRecordContractServerTiBO.setCreatorId(newFormRecord.getCreatorId());
                formRecordContractServerTiBO.setCreateTime(newFormRecord.getCreateTime());
                formRecordContractServerTiBO.setUpdateUserId(newFormRecord.getUpdateUserId());
                formRecordContractServerTiBO.setUpdateTime(newFormRecord.getUpdateTime());
                formRecordContractServerTiBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                formRecordContractServerTiBO.setBuildUnitCode(newFormRecord.getBuildUnitCode());
                formRecordContractServerTiBO.setContractId(newFormRecord.getId());
                formRecordContractServerTiDao.insert(formRecordContractServerTiBO);
            }
            //备案信息表_合同备案_应用系统_子表
            for(FormRecordContractSystemTiBO formRecordContractSystemTiBO : newFormRecord.getFormRecordContractSystemTiBOList()){
                formRecordContractSystemTiBO.setId(CommonTools.getUUID());
                formRecordContractSystemTiBO.setCreatorId(newFormRecord.getCreatorId());
                formRecordContractSystemTiBO.setCreateTime(newFormRecord.getCreateTime());
                formRecordContractSystemTiBO.setUpdateUserId(newFormRecord.getUpdateUserId());
                formRecordContractSystemTiBO.setUpdateTime(newFormRecord.getUpdateTime());
                formRecordContractSystemTiBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
                formRecordContractSystemTiBO.setBuildUnitCode(newFormRecord.getBuildUnitCode());
                formRecordContractSystemTiBO.setContractId(newFormRecord.getId());
                formRecordContractSystemTiDao.insert(formRecordContractSystemTiBO);
            }
            circulationDetailsService.saveCirculationDetails(newFormRecord.getId(), businessType, circulationStatus, newFormRecord.getBuildUnitCode(), handlingOpinions, userVO);
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        }else if(BusinessEnum.BUSINESS_TYPE_RECORD_ACCEPT.equals(businessType)){
            //验收备案
            //传入的数据
            FormRecordAcceptTBO newFormRecord = CommonTools.jsonStrToObject(formDataJson, FormRecordAcceptTBO.class);
            //数据库的数据
            FormRecordAcceptTBO oldFormRecord = formRecordAcceptTDao.selectByPrimaryKey(newFormRecord.getId());
            //结合数据库的数据对传入的数据进行完善然后覆盖数据库的数据
            newFormRecord.setCreatorId(oldFormRecord.getCreatorId());
            newFormRecord.setCreateTime(oldFormRecord.getCreateTime());
            newFormRecord.setUpdateUserId(userVO.getUserId());
            newFormRecord.setUpdateTime(new Date());
            newFormRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            newFormRecord.setBuildUnitCode(oldFormRecord.getBuildUnitCode());
            newFormRecord.setBusinessStatus(recordBusinessStatus);
            formRecordAcceptTDao.updateByPrimaryKey(newFormRecord);
            circulationDetailsService.saveCirculationDetails(newFormRecord.getId(), businessType, circulationStatus, newFormRecord.getBuildUnitCode(), handlingOpinions, userVO);
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        }else if(BusinessEnum.BUSINESS_TYPE_RECORD_FUNDS.equals(businessType)){
            //资金使用备案
            //传入的数据
            FormRecordFundsTBO newFormRecord = CommonTools.jsonStrToObject(formDataJson, FormRecordFundsTBO.class);
            //数据库的数据
            FormRecordFundsTBO oldFormRecord = formRecordFundsTDao.selectByPrimaryKey(newFormRecord.getId());
            //结合数据库的数据对传入的数据进行完善然后覆盖数据库的数据
            newFormRecord.setCreatorId(oldFormRecord.getCreatorId());
            newFormRecord.setCreateTime(oldFormRecord.getCreateTime());
            newFormRecord.setUpdateUserId(userVO.getUserId());
            newFormRecord.setUpdateTime(new Date());
            newFormRecord.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            newFormRecord.setBuildUnitCode(oldFormRecord.getBuildUnitCode());
            newFormRecord.setBusinessStatus(recordBusinessStatus);
            formRecordFundsTDao.updateByPrimaryKey(newFormRecord);

            //资金使用历史痕迹保存
            FormRecordFundsHistoryTBO formRecordFundsHistoryTBO = CommonTools.convertBean(newFormRecord, FormRecordFundsHistoryTBO.class);
            formRecordFundsHistoryTBO.setRecordFundsHistoryId(CommonTools.getUUID());
            formRecordFundsHistoryTDao.insert(formRecordFundsHistoryTBO);

            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        }
        return jsonResult;
    }

    @Override
    public JsonResult recordInfoObtain(JsonResult jsonResult, String buildUnitCode, UserVO userVO) {
        //用于存放备案信息的map
        Map map = new HashMap<String,Object>();

        //台账信息
        FormAccountInformationTBO formAccountInformationTBO = accountInformationDao.getAccountInformationByBuildUnitCode(buildUnitCode);


        //招投标备案业务信息
        FormRecordBidTBO formRecordBidTBO = formRecordBidTDao.getRecordBidByBuildUnitCode(buildUnitCode);
        Map bidCirculeInfo = new HashMap();
        if(formRecordBidTBO != null){
            //招投标备案流转信息
            bidCirculeInfo = circulationDetailsService.getCirculeInfo(formRecordBidTBO.getId(), formRecordBidTBO.getBusinessStatus());
        }else{
            formRecordBidTBO = new FormRecordBidTBO();
            bidCirculeInfo.put("handlingOpinionsShow","0");
            bidCirculeInfo.put("handlingOpinions",null);
        }

        //合同备案业务信息
        FormRecordContractTBO formRecordContractTBO = formRecordContractTDao.getRecordContractByBuildUnitCode(buildUnitCode);
        Map contractCirculeInfo = new HashMap();
        if(formRecordContractTBO != null){
            //合同备案流转信息
            contractCirculeInfo = circulationDetailsService.getCirculeInfo(formRecordContractTBO.getId(), formRecordContractTBO.getBusinessStatus());
        }else{
            formRecordContractTBO = new FormRecordContractTBO();
            FormRecordContractTerminalTiBO formRecordContractTerminalTiBO = new FormRecordContractTerminalTiBO();
            List<FormRecordContractTerminalTiBO> formRecordContractTerminalTiBOList = new ArrayList<>();
            formRecordContractTerminalTiBOList.add(formRecordContractTerminalTiBO);
            formRecordContractTBO.setFormRecordContractTerminalTiBOList(formRecordContractTerminalTiBOList);

            FormRecordContractSystemTiBO formRecordContractSystemTiBO = new FormRecordContractSystemTiBO();
            List<FormRecordContractSystemTiBO> formRecordContractSystemTiBOList = new ArrayList<>();
            formRecordContractSystemTiBOList.add(formRecordContractSystemTiBO);
            formRecordContractTBO.setFormRecordContractSystemTiBOList(formRecordContractSystemTiBOList);

            FormRecordContractServerTiBO formRecordContractServerTiBO = new FormRecordContractServerTiBO();
            List<FormRecordContractServerTiBO> formRecordContractServerTiBOList = new ArrayList<>();
            formRecordContractServerTiBOList.add(formRecordContractServerTiBO);
            formRecordContractTBO.setFormRecordContractServerTiBOList(formRecordContractServerTiBOList);

            contractCirculeInfo.put("handlingOpinionsShow","0");
            contractCirculeInfo.put("handlingOpinions",null);
        }

        //资金使用情况备案业务信息
        FormRecordFundsTBO formRecordFundsTBO = formRecordFundsTDao.getRecordFundsByBuildUnitCode(buildUnitCode);
        Map fundsCirculeInfo = new HashMap();
        if(formRecordFundsTBO != null){
            //资金使用情况备案流转信息
            fundsCirculeInfo = circulationDetailsService.getCirculeInfo(formRecordFundsTBO.getId(), formRecordFundsTBO.getBusinessStatus());
        }else{
            formRecordFundsTBO = new FormRecordFundsTBO();
            fundsCirculeInfo.put("handlingOpinionsShow","0");
            fundsCirculeInfo.put("handlingOpinions",null);
        }

        //验收备案
        FormRecordAcceptTBO formRecordAcceptTBO = formRecordAcceptTDao.getRecordAcceptByBuildUnitCode(buildUnitCode);
        Map acceptCirculeInfo = new HashMap();
        if(formRecordAcceptTBO != null){
            //验收备案流转信息
            acceptCirculeInfo = circulationDetailsService.getCirculeInfo(formRecordAcceptTBO.getId(), formRecordAcceptTBO.getBusinessStatus());
        }else{
            formRecordAcceptTBO = new FormRecordAcceptTBO();
            acceptCirculeInfo.put("handlingOpinionsShow","0");
            acceptCirculeInfo.put("handlingOpinions",null);
        }


        map.put("formAccountInformationTBO",formAccountInformationTBO);
        map.put("formRecordBidTBO",formRecordBidTBO);
        map.put("bidCirculeInfo",bidCirculeInfo);
        map.put("formRecordContractTBO",formRecordContractTBO);
        map.put("contractCirculeInfo",contractCirculeInfo);
        map.put("formRecordFundsTBO",formRecordFundsTBO);
        map.put("fundsCirculeInfo",fundsCirculeInfo);
        map.put("formRecordAcceptTBO",formRecordAcceptTBO);
        map.put("acceptCirculeInfo",acceptCirculeInfo);
        jsonResult.setData(map);
        CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        return jsonResult;
    }

    @Override
    public JsonPageResult getRecordInformationList(JsonPageResult jsonResult, int currentPage, int pageSize, String buildUnitName, String businessStatus, String businessType, UserVO userVO) {
        String unitCode = userVO.getUnitCode();
        FormBuildUnitTBO formBuildUnitTBO = new FormBuildUnitTBO();
        formBuildUnitTBO.setBuildUnitCode(unitCode);
        formBuildUnitTBO = formBuildUnitTDao.selectOne(formBuildUnitTBO);
        if(StringUtils.isEmpty(formBuildUnitTBO.getBuildUnitType())){
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_USER_UNDO);
            return jsonResult;
        }

        if (currentPage <= 0) {
            currentPage = 1;
        }
        if(StringUtils.isEmpty(businessStatus)){
            businessStatus = null;
        }
        if(StringUtils.isEmpty(businessType)){
            businessType = null;
        }
        if(StringUtils.isEmpty(buildUnitName)){
            buildUnitName = null;
        }

        Map map = new HashMap();
        map.put("currentPage",currentPage);
        map.put("pageSize",pageSize);
        map.put("businessStatus",businessStatus);
        map.put("businessType",businessType);
        map.put("buildUnitName",buildUnitName);

        if(BusinessEnum.BUILD_UNIT_TYPE_SUPERIOR.getValue().equals(formBuildUnitTBO.getBuildUnitType())){
           //上级单位
            map.put("buildUnitCode",null);
        }else if(BusinessEnum.BUILD_UNIT_TYPE_SUBORDINATE.getValue().equals(formBuildUnitTBO.getBuildUnitType())){
            //下级单位
            map.put("buildUnitCode",unitCode);
        }
        //返回前端的具体的数据
        List list = null;
        //符合展示条件的数据总数
        Integer total = null;
        total = recordInformationDao.queryRecordInfoShowNum(map);
        list = recordInformationDao.pagingQueryRecordInfoList(map);
        if(total==null){
            total=0;
        }
        //计算一共多少页
        Integer pageNum = (total%pageSize==0)?(total/pageSize):(total/pageSize+1);

        jsonResult.setData(list);
        jsonResult.setCurrentPage(currentPage);
        jsonResult.setPageSize(pageSize);
        jsonResult.setTotalCount(total);
        jsonResult.setTotalPage(pageNum);
        if(list == null || list.size()==0){
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_NONEXISTENT_DATA);
        }else{
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        }
        return jsonResult;
    }


    @Override
    @Transactional
    public JsonResult saveContract(JsonResult jsonResult, String formDataJson, UserVO userVO) throws Exception{
        FormRecordContractTBO formRecordContractTBO = CommonTools.jsonStrToObject(formDataJson, FormRecordContractTBO.class);

        String creatorId = userVO.getUserId();
        Date createTime = new Date();
        String updateUserId = userVO.getUserId();
        Date updateTime = new Date();
        String buildUnitCode = formRecordContractTBO.getBuildUnitCode();

        formRecordContractTBO.setId(CommonTools.getUUID());
        formRecordContractTBO.setCreatorId(creatorId);
        formRecordContractTBO.setCreateTime(createTime);
        formRecordContractTBO.setUpdateUserId(updateUserId);
        formRecordContractTBO.setUpdateTime(updateTime);
        formRecordContractTBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
        formRecordContractTDao.insert(formRecordContractTBO);
        //备案信息表_合同备案_终端_子表
        for(FormRecordContractTerminalTiBO formRecordContractTerminalTiBO : formRecordContractTBO.getFormRecordContractTerminalTiBOList()){
            formRecordContractTerminalTiBO.setId(CommonTools.getUUID());
            formRecordContractTerminalTiBO.setCreatorId(creatorId);
            formRecordContractTerminalTiBO.setCreateTime(createTime);
            formRecordContractTerminalTiBO.setUpdateUserId(updateUserId);
            formRecordContractTerminalTiBO.setUpdateTime(updateTime);
            formRecordContractTerminalTiBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            formRecordContractTerminalTiBO.setBuildUnitCode(buildUnitCode);
            formRecordContractTerminalTiBO.setContractId(formRecordContractTBO.getId());
            formRecordContractTerminalTiDao.insert(formRecordContractTerminalTiBO);
        }
        //备案信息表_合同备案_服务器_子表
        for(FormRecordContractServerTiBO formRecordContractServerTiBO : formRecordContractTBO.getFormRecordContractServerTiBOList()){
            formRecordContractServerTiBO.setId(CommonTools.getUUID());
            formRecordContractServerTiBO.setCreatorId(creatorId);
            formRecordContractServerTiBO.setCreateTime(createTime);
            formRecordContractServerTiBO.setUpdateUserId(updateUserId);
            formRecordContractServerTiBO.setUpdateTime(updateTime);
            formRecordContractServerTiBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            formRecordContractServerTiBO.setBuildUnitCode(buildUnitCode);
            formRecordContractServerTiBO.setContractId(formRecordContractTBO.getId());
            formRecordContractServerTiDao.insert(formRecordContractServerTiBO);
        }
        //备案信息表_合同备案_应用系统_子表
        for(FormRecordContractSystemTiBO formRecordContractSystemTiBO : formRecordContractTBO.getFormRecordContractSystemTiBOList()){
            formRecordContractSystemTiBO.setId(CommonTools.getUUID());
            formRecordContractSystemTiBO.setCreatorId(creatorId);
            formRecordContractSystemTiBO.setCreateTime(createTime);
            formRecordContractSystemTiBO.setUpdateUserId(updateUserId);
            formRecordContractSystemTiBO.setUpdateTime(updateTime);
            formRecordContractSystemTiBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            formRecordContractSystemTiBO.setBuildUnitCode(buildUnitCode);
            formRecordContractSystemTiBO.setContractId(formRecordContractTBO.getId());
            formRecordContractSystemTiDao.insert(formRecordContractSystemTiBO);
        }
        CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        return jsonResult;
    }

    @Override
    public JsonResult getContractListByBuildUnitCode(JsonResult jsonResult, String buildUnitCode) {
        List<FormRecordContractTBO> formRecordContractTBOList = null;
/*        try{
            formRecordContractTBOList = formRecordContractTDao.getRecordContractByBuildUnitCode(buildUnitCode);
            if(formRecordContractTBOList==null){
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_NONEXISTENT_DATA);
            }else{
                jsonResult.setData(formRecordContractTBOList);
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
            }
        }catch (Exception e){
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }*/
        return jsonResult;
    }

    @Override
    public JsonResult saveBid(JsonResult jsonResult, String formDataJson, UserVO userVO) {
        FormRecordBidTBO formRecordBidTBO = null;
        try {
            formRecordBidTBO =  CommonTools.jsonStrToObject(formDataJson, FormRecordBidTBO.class);

            String creatorId = userVO.getUserId();
            Date createTime = new Date();
            String updateUserId = userVO.getUserId();
            Date updateTime = new Date();

            formRecordBidTBO.setId(CommonTools.getUUID());
            formRecordBidTBO.setCreatorId(creatorId);
            formRecordBidTBO.setCreateTime(createTime);
            formRecordBidTBO.setUpdateUserId(updateUserId);
            formRecordBidTBO.setUpdateTime(updateTime);
            formRecordBidTBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            formRecordBidTDao.insert(formRecordBidTBO);
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }
        return jsonResult;
    }

    @Override
    public JsonResult getBidListByBuildUnitCode(JsonResult jsonResult, String buildUnitCode) {
        List<FormRecordBidTBO>  formRecordBidTBOList = null;
/*        try{
            formRecordBidTBOList = formRecordBidTDao.getRecordBidByBuildUnitCode(buildUnitCode);
            if(formRecordBidTBOList==null){
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_NONEXISTENT_DATA);
            }else{
                jsonResult.setData(formRecordBidTBOList);
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
            }
        }catch (Exception e){
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }*/

        return jsonResult;
    }

    @Override
    public JsonResult saveAccept(JsonResult jsonResult, String formDataJson, UserVO userVO) {
        FormRecordAcceptTBO formRecordAcceptTBO = null;
        try {
            formRecordAcceptTBO =  CommonTools.jsonStrToObject(formDataJson, FormRecordAcceptTBO.class);
            String creatorId = userVO.getUserId();
            Date createTime = new Date();
            String updateUserId = userVO.getUserId();
            Date updateTime = new Date();

            formRecordAcceptTBO.setId(CommonTools.getUUID());
            formRecordAcceptTBO.setCreatorId(creatorId);
            formRecordAcceptTBO.setCreateTime(createTime);
            formRecordAcceptTBO.setUpdateUserId(updateUserId);
            formRecordAcceptTBO.setUpdateTime(updateTime);
            formRecordAcceptTBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            formRecordAcceptTDao.insert(formRecordAcceptTBO);
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }
        return jsonResult;
    }

    @Override
    public JsonResult getAcceptListByBuildUnitCode(JsonResult jsonResult, String buildUnitCode) {
        List<FormRecordAcceptTBO>  formRecordAcceptTBOList = null;
/*        try{
            formRecordAcceptTBOList = formRecordAcceptTDao.getRecordAcceptByBuildUnitCode(buildUnitCode);
            if(formRecordAcceptTBOList==null){
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_NONEXISTENT_DATA);
            }else{
                jsonResult.setData(formRecordAcceptTBOList);
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
            }
        }catch (Exception e){
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }*/
        return jsonResult;
    }

    @Override
    public JsonResult saveFunds(JsonResult jsonResult, String formDataJson, UserVO userVO) {
        FormRecordFundsTBO formRecordFundsTBO = null;
        try {
            formRecordFundsTBO =  CommonTools.jsonStrToObject(formDataJson, FormRecordFundsTBO.class);
            String creatorId = userVO.getUserId();
            Date createTime = new Date();
            String updateUserId = userVO.getUserId();
            Date updateTime = new Date();

            formRecordFundsTBO.setId(CommonTools.getUUID());
            formRecordFundsTBO.setCreatorId(creatorId);
            formRecordFundsTBO.setCreateTime(createTime);
            formRecordFundsTBO.setUpdateUserId(updateUserId);
            formRecordFundsTBO.setUpdateTime(updateTime);
            formRecordFundsTBO.setIsDelete(BusinessEnum.IS_DELETE_N.getValue());
            formRecordFundsTDao.insert(formRecordFundsTBO);
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }
        return jsonResult;
    }

    @Override
    public JsonResult getFundsListByBuildUnitCode(JsonResult jsonResult, String buildUnitCode) {
        List<FormRecordFundsTBO>  formRecordFundsTBOList = null;
/*        try{
            formRecordFundsTBOList = formRecordFundsTDao.getRecordFundsByBuildUnitCode(buildUnitCode);
            if(formRecordFundsTBOList==null){
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_NONEXISTENT_DATA);
            }else{
                jsonResult.setData(formRecordFundsTBOList);
                CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_SUCCESS);
            }
        }catch (Exception e){
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }*/
        return jsonResult;
    }


}
